import request from '@/utils/request'

interface FetchGaitDataParams {
  table_name: string
  record_id: string
}

export interface FetchGaitDataResponse {
  status: string
  code: number
  message: string
  data: {
    procedural_events: Proceduralevent[]
    walk_segments: Walksegment[]
  }
}

interface Walksegment {
  segment_id: number
  start_frame: number
  end_frame: number
  calculated_metrics: Calculatedmetrics
  events: Proceduralevent[]
}

interface Calculatedmetrics {
  gait_speed: number
  stride_length: number
  step_speed: number
  swing_speed: number
  cadence: number
  single_support_phase_ratio: number
  swing_phase_ratio: number
  double_support_ratio: number
  step_height: number
  step_width: number
}

interface Proceduralevent {
  event: string
  frame: number
}

/**
 * 获取步态分析数据
 * @param params 请求参数
 * @returns
 */
export const fetchGaitData = ({
  table_name,
  record_id,
}: FetchGaitDataParams): Promise<FetchGaitDataResponse> => {
  return request({
    url: `/v3/admin/logs/${table_name}/${record_id}/gait`,
    method: 'get',
  })
}

/**
 * 编辑步态分析数据
 * @param table_name
 * @param record_id
 * @returns
 */
export const editGaitData = (
  table_name: string,
  record_id: string,
  data: Proceduralevent[],
): Promise<FetchGaitDataResponse> => {
  return request({
    url: `/v3/admin/logs/${table_name}/${record_id}/gait/events`,
    method: 'post',
    data,
  })
}

/**
 * 删除当前帧
 * @param table_name
 * @param record_id
 * @returns
 */
export const deleteGaitData = (table_name: string, record_id: string) => {
  return request({
    url: `/v3/admin/logs/${table_name}/${record_id}/gait/events`,
    method: 'delete',
  })
}
